package org.javaboy.system_task.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

@RestController
public class HelloController {
    @Autowired
    ApplicationArguments args;
    @GetMapping("/hello")
    public void hello() {
        //获取所有的参数，无论是 key-value 格式还是非 key-value 格式
        String[] sourceArgs = args.getSourceArgs();
        System.out.println("Arrays.toString(sourceArgs) = " + Arrays.toString(sourceArgs));
        Set<String> optionNames = args.getOptionNames();
        for (String optionName : optionNames) {
            System.out.println(optionName + ">>>" + args.getOptionValues(optionName));
        }
        List<String> nonOptionArgs = args.getNonOptionArgs();
        System.out.println("nonOptionArgs = " + nonOptionArgs);
    }
}
